<?php
require('conn.php');
require('session.php');
require('functions.php');
//print_r($userdata);
$uid=guolv($_GET['uid']);
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
        <meta name="format-detection" content="telephone=no">
        <meta http-equiv="Cache-Control" content="max-age=0">
        <meta name="apple-touch-fullscreen" content="yes">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <title>开始赚钱</title>
        <meta name="description" content="<?php echo $config['sitename']?>">
        <meta name="keywords" content="<?php echo $config['sitename']?>" />
        <link rel="stylesheet" href="static/css/font-awesome.min.css" />
        <link rel="stylesheet" href="static/all.css">
        <style>
           .active{
             background-color: white!important;
             color: #f74545!important;
           }
        </style>
    </head>
    <body class="withHeader">
        <div class="positionFooter">
            <ul style="height:100%;">
                <li><a class="a1" href="<?php echo $site?>/ucenter.php"></a></li>   
                <li><a class="a5" href="<?php echo $site?>/list.php?uid=<?php echo $uid?>"></a></li>
                <li><a class="a3" href="<?php echo $site?>/news.php?type=1"></a></li>
            </ul>
        </div>
        <header>
            <div class="top_menu_bar" style="z-index: 100">
                <div class="top_menu">
                    <div class="top_menu_list">
                    <a href="#new" class="btn alist active">最新</a>
                    <?php
                    $rows_type=$mysql->query("select * from `typedata` order by `id`");
                    foreach($rows_type as $key=>$v_type){
                            echo "<a href=\"#{$v_type['id']}\" class=\"btn alist\" title=\"{$v_type['id']}\">{$v_type['name']}</a>";
                    }
                    ?>
                    </div>
                </div>
            </div>
        </header>
        <div class="list_content" style="z-index:9;padding-top:51px;height: auto;"> 
</div>
<div id="loading" class="loading-wrap">
     <span class="loading">加载中，请稍后...</span>
</div>
<?php
    @session_start();
    if(isset($_SESSION)){
        $_uid=$_SESSION['userdata']['id'];
    }else{
        $_uid=guolv($_GET['uid']);
    }
?>
<br><br><br>
<script src="static/jquery-2.2.0.min.js"></script>
<script src="static/jquery.touch.js"></script>
<script>
$(function(){
    var loading = $("#loading");
    var last = true;
    var uid='<?php echo $uid?>';
    var order='<?php echo $config['ListOrder']?>';
    var type;
    var page=2;
    var hash=window.location.hash;

    if (hash) {
        type=hash.substr(1);
        if (type=='new') {
             addList(type,uid,order);
        }
        $('.alist').removeClass('active');
        $("a[href$='#"+type+"']").addClass('active');
             addList(type,uid);
    }else{
             addList(type,uid,order);
         }


    // addList(type,uid,order);
    $('.alist').on('tap', function(event) {
        if ($(this).hasClass('active')) {
        } else {
            $('.alist').removeClass('active');
            $(this).addClass('active');
            type=$(this).attr('title');
            // if (order) {
                    // addList(type,uid,order);
            // }
            addList(type,uid);
        }
    });
    $(window).scroll(function(){
        if($(document).scrollTop() >= $(document).height()-$(window).height() && last){
            setTimeout(function(){
            //加载更多数据
            last = false;
            $.ajax({
                url: '<?php echo $config["site"] ?>/api/addlist.php',
                type: 'GET',
                dataType: "json",
                data: {
                    page: page,
                    type: type,
                    uid: uid,
                },
            })
            .done(function(data) {
                // console.log(data);
            for (var i in data) {
                string = ' <section class="middle_mode has_action"> ';
                string+= '<a href="http://<?php echo $sharesite?>/detail.php?aid='+data[i].id+'&uid=<?php echo $uid?>" class="article_link clearfix">';         
               
                string+='<h3>'+data[i].title+'</h3><div class="list_img_holder"><img src=http://img01.store.sogou.com/net/a/04/link?appid=100520031&w=135&h=90&url='+data[i].pic.substring(8)+' style="opacity: 1;"></div><div class="item_info"><span class="cmt">阅读：'+data[i].pv+'</span>'
                string+='<span class="agree" style="display: none"><i class="fa fa-thumbs-up"></i> 925</span><span title="2015-06-30" class="time" style="display: none">06-30 20:10</span></div></a></section>'

            $('.list_content').append(string);
            last = true;
            };
            // console.log(string);
            if(data==''){
              last = false;
            }
            page++;
            })
            .always(function(data){
            loading.fadeIn(300).delay(200).fadeOut(10);
            })
                
            },300)
            //加载更多数据
        }    });

    function addList(type,uid,order){
            $('.list_content').empty();
            this.type=type;
            this.uid=uid;
            this.order=order;
            last = false;
            setTimeout(function(){
            $.ajax({
                url: '<?php echo $config["site"] ?>/api/addlist.php',
                type: 'GET',
                dataType: "json",
                data: {
                    page: 1,
                    type: this.type,
                    uid: this.uid,
                    do: this.order,
                },
            })
            .done(function(data) {
                // console.log(data);
            for (var i in data) {
                string = ' <section class="middle_mode has_action"> ';
                string+= '<a href="<?php echo $config["site"] ?>/detail.php?aid='+data[i].id+'&uid=<?php echo $uid?>" class="article_link clearfix">';         
               
                string+='<h3>'+data[i].title+'</h3><div class="list_img_holder"><img src=http://img01.store.sogou.com/net/a/04/link?appid=100520031&w=135&h=90&url='+data[i].pic.substring(8)+' style="opacity: 1;"></div><div class="item_info"><span class="cmt">阅读：'+data[i].pv+'</span>'
                string+='<span class="agree" style="display: none"><i class="fa fa-thumbs-up"></i> 925</span><span title="2015-06-30" class="time" style="display: none">06-30 20:10</span></div></a></section>'

            $('.list_content').append(string);
            last = true;
            };
            // $('html,body').animate({
            //     scrollTop : '0px'
            // },500);  
            // console.log(string);
            if(data==''){
              last = false;
            }
            page=2;
            })
            },300)
    }
});
</script>
<?php

$mysql->__destruct();
$mysql->close();
?>
</body>
</html>